#include "mylog.h"
#include "ui_mylog.h"

myLog::myLog(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::myLog)
{
    ui->setupUi(this);

    this->setFixedSize(this->size());//锁定窗口大小

    //初始化数据库设置
    m_db = QSqlDatabase::addDatabase("QMYSQL");
    m_db.setDatabaseName("db_recSys");
    m_db.setHostName("localhost");
    m_db.setUserName("root");
    m_db.setPassword("KWP-ffmxyr0");
    if(m_db.open() == false){//如果连接失败
        QMessageBox::warning(0,"警告","数据库初始化失败.");
        delete this;
    }
}

myLog::~myLog()
{
    delete ui;
}

void myLog::on_pushButton_clicked()
{
    if(ui->editAccount->text().isEmpty() || ui->editPswd->text().isEmpty()){//如果账号或密码为空
        return;
    }

    QSqlQuery query;
    query.exec("select pswd from tb_admin where account='"+ui->editAccount->text()+"';");
    query.first();
    if(query.value("pswd").toString() == ui->editPswd->text()){//如果账号密码正确
        MainWindow w(&m_db,this);
        w.show();
//        this->hide();
    }
}
